package com.igoal.service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.igoal.dto.CommentDTO;
import com.igoal.dto.Commentable;
import com.igoal.entity.ComponentEnum;

/**
 * All service of comment
 * @author tri
 *
 */
public interface CommentService{
	/**
	 * Get comment dto by id 
	 * @param id comment identifier
	 * @return {@link CommentDTO} or null
	 */
	@Transactional(readOnly=true)
	CommentDTO loadComment(Long id);
	
	/**
	 * Get all comments of a component 
	 * @param componentId component identifier
	 * @param component component type
	 * @return list of {@link CommentDTO} or empty list
	 */
	@Transactional(readOnly=true)
	List<CommentDTO> loadAllCommentsBefore(Long componentId, ComponentEnum component, long updateBefore);
	
	/**
	 * Get comments by page 
	 * @param componentId component identifier
	 * @param component component type
	 * @param lastCommentOfPreviousPageDate order value
	 * @param before previous page
	 * @return list of {@link CommentDTO} or empty list
	 */
	//@Transactional(readOnly=true)
	//List<CommentDTO> loadComponentCommentsByPage(Long componentId, ComponentEnum component, Date lastCommentOfPreviousPageDate, boolean before);
	
	@Transactional(readOnly=true)
	List<CommentDTO> getLatestComments(Long componentId, ComponentEnum component);
	
	/**
	 * Inject comment list to commentable item 
	 * @param item {@link Commentable}
	 * @param component {@link ComponentEnum}
	 */
	//@Transactional(readOnly=true)
	void loadComments(Commentable item, ComponentEnum component);
	
	/**
	 * Add a comment
	 * @param dto
	 * @param username comment owner
	 * @return new comment id or -1 if failed to save
	 */
	@Transactional(readOnly=false)
	Long addComment(CommentDTO dto, String username);
	
	/**
	 * Delete a comment
	 * @param commentId comment identifier
	 * @param whoDelete username of who want to delete. <br/>Only can delete if whoDelete own this comment or own the component
	 * @return {@link SaveResult}
	 */
	@Transactional(readOnly=false)
	int deleteComment(Long commentId, String whoDelete);
}
